<?php

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

use \GatewayWorker\Lib\Gateway;

use Illuminate\Support\Facades\DB;
use Cache;
use Validator;
use Carbon\Carbon;

use  App\Models\CallRecord;

class CallRecordController extends Controller
{
    public function create(Request $request)
    {
        $input = Input::only('file_url','call_type','phone_number','called_number','started_at','end_at','hold_time','imei');
        $validator = Validator::make($input, [        
            'file_url' => 'nullable',
            'call_type' => 'nullable',
            'phone_number' => 'nullable',
            'called_number' => 'nullable',
            'started_at' => 'nullable',
            'end_at' => 'nullable',
            'hold_time' => 'nullable',
            'imei' => 'nullable',
        ]);
        if ($validator->fails()) {
            return $this->returnError([],401,'参数错误');
        }
        // msg_type
        $data['file_url'] = $input['file_url']??'';
        if(isset($input['call_type'])){
            $data['call_type'] = $input['call_type'];
        }
        $data['phone_number'] = $input['phone_number']??'';
        $data['called_number'] = $input['called_number']??'';
        $data['started_at'] = $input['started_at']??'';
        $data['end_at'] = $input['end_at']??'';
        $data['hold_time'] = $input['hold_time']??'';
        $data['imei'] = $input['imei']??0;
        // WeixinFriendList::where('')
        $res = CallRecord::create($data);
        return $this->returnOk([],'上传成功');
    }
}